function run_ccm_wnn(k)
load mnist_knn_cos;
load mnist_label;
load mnist_train;
load mnist_data;

l = 60000;
n = size(Y,1);
Yt = Y(1:l);
Ys = Y(l+1:n);
tic
cls = unique(Y);
c = size(cls,1);

disp('Start optimization...');
options = optimoptions('quadprog','Algorithm','trust-region-reflective');

fai = zeros(n,c);

for i = 1:c
    disp(['Training class: ',int2str(i)]);
    ipos = find(Yt==cls(i));
    lpos = length(ipos);
    ineg = find(Yt~=cls(i));
    lneg = length(ineg);
    Yl = -inf*ones(n,1);
    Yu = inf*ones(n,1);
    Yl(ipos) = ones(lpos,1);
    Yu(ineg) = -ones(lneg,1);
    Yl(ipos) = ones(lpos,1);
    Yu(ineg) = -ones(lneg,1);
    [U,~] = svd(Xl(ipos,:)',0);
    w = U(:,1);
    wet = zeros(n,k);
    for j = 1:n
        x = X(j,:);
        Xn = X(nn(j,1:k),:);
        Z = Xn-repmat(x,k,1);
        wet(j,:) = (exp(-(Z.*Z)*w))';
    end
    L = knn2lap(nn(:,1:k),wet);
    x0 = zeros(n,1);
    x0(ipos) = ones(lpos,1);
    x0(ineg) = -ones(lneg,1);
    fai(:,i) = quadprog(L,[],[],[],[],[],Yl,Yu,x0,options);
end

[~,Cp] = max(fai,[],2);
Yp = cls(Cp);

slvtime = toc
trerr = calerr(Yp(1:l),Yt)
tserr = calerr(Yp(l+1:n),Ys)
%exit
end
